local jiefan = fk.CreateSkill {
    name = "SP_heg__jiefan",
}

Fk:loadTranslationTable {
    ["SP_heg__jiefan"] = "解烦",
    [":SP_heg__jiefan"] = "当你使用【杀】造成伤害后，你可以将一张装备牌当【桃】对一名已受伤角色使用，若此牌为武器牌，其将手牌摸至此牌的攻击范围。",

    ["#SP_heg__jiefan-choose"] = "解烦：选择一张装备牌和一名已受伤角色，将此装备牌当【桃】对其使用",

    ["$SP_heg__jiefan1"] = "一箭可解之事，何使公忧烦至此。",
    ["$SP_heg__jiefan2"] = "贼盛不足惧，有吾解烦营。",
}

jiefan:addEffect(fk.Damage, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(jiefan.name) and data.card and data.card.trueName == "slash"
            and #player:getCardIds("h") > 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players,
            function(p)
                return p:isWounded() and player:canUseTo(Fk:cloneCard("peach"), p)
            end)
        if #targets == 0 then return end
        local tos, cards = room:askToChooseCardsAndPlayers(player, {
            min_card_num = 1,
            max_card_num = 1,
            min_num = 1,
            max_num = 1,
            targets = targets,
            skill_name = jiefan.name,
            pattern = ".|.|.|equip|.|.|.",
            prompt = "#SP_heg__jiefan-choose",
            cancelable = true,
        })
        if #tos > 0 and #cards > 0 then
            event:setCostData(self, { tos = tos, cards = cards })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local card = event:getCostData(self).cards
        local to = event:getCostData(self).tos[1]
        local n = math.max(table.unpack(table.map(player:getEquipments(Card.SubtypeWeapon), function(id)
            return Fk:getCardById(id):getAttackRange(player)
        end)))
        room:useVirtualCard("peach", card, player, to, jiefan.name)
        local num = math.min(n, 5) - to:getHandcardNum()
        if num > 0 then
            to:drawCards(num, jiefan.name)
        end
    end,
})

return jiefan
